import { defineStore } from "pinia";

export const useCouponStore = defineStore('coupon', {
    state: () => {
        return {
            num: null
        }
    },
    getters: {},
    actions: {
        setNum(payload) {
            this.num = payload
        }
    }
})

export const useBuyNumber = defineStore('BuyNumber', {
    state: () => ({
        totalValue:null,
        buyNum: null,
        money: 0,
        arr: []
        // arr: [
        //     {
        //         id: 1,
        //         value: 0,
        //         money:10
        //     },
        //     {
        //         id: 2,
        //         value: 0,
        //         money: 20
        //     },
        //     {
        //         id: 3,
        //         value: 0,
        //         money: 30
        //     },
        //     {
        //         id: 4,
        //         value: 0,
        //         money: 40
        //     },
        // ]
    }),
    getters: {

    },

    actions: {
        totalMoney(id) {
            this.money = 0
            this.arr.forEach(i => {
                    this.money += i.money * i.value
            })

        },
        totalBuyNum(id) {
            this.totalValue = 0
            this.arr.forEach(i => {
                this.totalValue += i.value
            })
            console.log(this.totalValue)
            console.log(this.arr)

        },
        subNum(id) {
            if (this.arr[id - 1].value == 0) return
            // console.log(id)
            // console.log(this.arr.value)
            this.arr.forEach(i => {
                if (i.coupon_id == id) { i.value-- }
            })
        },
        addNum(id) {
            this.value++
            this.arr.forEach(i => {
                if (i.coupon_id == id) { i.value++ }
            })
        },
        getBuyNum(payload) {
            this.buyNum = payload
        },
        setMoney(payload) {
            // 21是优惠券上的价钱
            this.money = payload
        },
        setValue(payload) {
            this.value = payload
        }
    }
})

export const useConfirmOrder = defineStore('ConfirmOrder', {
    state: () => {
        return {
            arr1: [
                {
                    count: 1,
                    value: 0,
                    money: 10
                },
                {
                    count: 0
                },
                {
                    count: 0
                },
            ]
        }
    },
    getters: {},
    actions: {

    }
})